#!/usr/bin/env python

import sys

def function(n):
    if n < 3:
        return n
    else:
        a = 2
        b = 1
        c = 0
        sum = 0
        for i in range(n - 2):
            sum = a + 2*b + 3*c
            c = b
            b = a
            a = sum
        return sum

